package models

import (
	"time"
)

// User 用户表
type User struct {
	ID        int       `gorm:"primaryKey;autoIncrement;column:id"`
	Username  string    `gorm:"type:varchar(50);not null;column:username"`
	Phone     string    `gorm:"type:char(11);uniqueIndex:idx_users_phone;not null;column:phone"`
	Password  string    `gorm:"type:varchar(255);not null;column:password"`
	Status    int64     `gorm:"not null;default:0;column:status"`
	Role      int64     `gorm:"not null;default:0;column:role"`
	CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP;column:created_at"`
	UpdatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP;column:updated_at"`
}

func (*User) TableName() string {
	return "users"
}

func (u *User) ToResponse() map[string]any {
	return map[string]any{
		"id":         u.ID,
		"username":   u.Username,
		"status":     u.Status,
		"role":       u.Role,
		"created_at": u.CreatedAt,
		"updated_at": u.UpdatedAt,
	}
}
